package spring.core.examples.xml;

import org.springframework.context.support.ClassPathXmlApplicationContext;

import spring.core.extensions.SpringApplicatonContext;

/**
 * Wrapper to always return a reference to the Spring Application Context from
 * within non-Spring enabled beans. Usually this class will be instantiated
 * inside the Spring context and because it is context aware will then provide
 * access to the beans within the context. Spring context must be up and running
 * to make this work. If Spring context is not up and running this class will
 * ramp up a default context.
 */
public class CoreContext extends SpringApplicatonContext {
	private static CoreContext INSTANCE = new CoreContext();

	/**
	 * Gets the single instance of ValidatorContext.
	 * 
	 * @return single instance of ValidatorContext
	 */
	public static CoreContext getInstance() {
		return CoreContext.INSTANCE;
	}

	@Override
	protected void registerDefaultApplicatonContext() {
		this.setApplicationContext(new ClassPathXmlApplicationContext(
				"my-beans.xml"));
		System.out.println("Verwende default Spring Kontext.");
	}

}
